<!--
* description: 备件采购订单查询_网点
* author: hm
* createdDate: 
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="true"
      :dynamic-is-show-more-btn="true"
      :dynamic-is-init-table="true"
      :callback-obj="callbackObj"
    >
      <!-- <template #rejectReason="scope">
        <el-input v-model="scope.row['rejectReason']" placeholder="驳回原因" clearable>
        </el-input>
      </template> -->
      <!-- <template #remark="scope">
        <el-input v-model="scope.row['remark']" placeholder="备注" clearable>
        </el-input>
      </template> -->
    </one-table-template>
    <select-detail
      :is-view-pop-windows="isViewPopWindows"
      :dynamic-edit-row-data="editRowData"
      @close="close"
    />
  </div>
</template>

<script>
import { formMixins } from '@/components/mixins/formMixins'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/vehicleManagement'
import SelectDetail from './selectDetail'
import { vehiclePdiPriceInquirys } from '@/api/se/vehiclePdiPriceInquiry'
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: 'PartOrderBranchAudit',
  components: {
    OneTableTemplate,
    SelectDetail
  },
  mixins: [oneTableWithViewTemplateMixins, formMixins],
  data() {
    null
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      selectiondata: [],
      isViewPopWindows: false,
      editRowData: {},
      apiConfig: vehiclePdiPriceInquirys.queryPartPurOrder,
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'controlBtn',
              label: '操作', // 操作
              codeField: 'controlBtn',
              width: 100,
              align: 'center',
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '查看明细', // 编辑
                  align: 'center',
                  codeField: 'editControlBtn',
                  clickEvent: index => {
                    this.isViewPopWindows = true
                    this.editRowData = this.$utils.deepCopy(
                      this.$refs['multipleTable'].list[index]
                    )
                  },
                  component: () => import('@/components/org/linkButton')
                }
              ]
            },
            {
              prop: 'purOrderCode',
              label: '订单号',
              align: 'center'
            },
            {
              prop: 'purOrderTypeCn',
              label: '订单类型',
              align: 'center'
            },
            {
              prop: 'purDate',
              label: '订货日期',
              align: 'center'
            },
            {
              prop: 'orderVariety',
              label: '订货品种数',
              align: 'center'
            },
            {
              prop: 'purAmount',
              label: '订货金额',
              align: 'center'
            },
            // {
            //   prop: 'transportModeName',
            //   label: '运输方式',
            //   align: 'center'
            // },
            {
              prop: 'supplierShortName',
              label: '供应商',
              align: 'center'
            },
            {
              prop: 'orderStatusCn',
              label: '订单状态',
              align: 'center'
            },
            // {
            //   prop: 'createdDate',
            //   label: '提交时间',
            //   align: 'center'
            // },
            // {
            //   prop: 'creator',
            //   label: '提交人',
            //   align: 'center'
            // },
            {
              prop: 'dlrAuditDate',
              label: '网点审核时间',
              align: 'center'
            },
            {
              prop: 'dlrAuditor',
              label: '网点审核人',
              align: 'center'
            },
            {
              prop: 'remark',
              label: '备注',
              align: 'center',
              // isSlot: true,
              width: 150
            }
          ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 库存状态
            {
              compKey: 'compKey11',
              labelName: '订单号：',
              codeField: 'purOrderCode',
              lookuptype: 'VE0212',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey12',
              labelName: '订货日期：',
              codeField: 'startDate,endDate',
              component: () => import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMul: true,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey13',
              labelName: '订单类型：',
              codeField: 'purOrderType',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: vehiclePdiPriceInquirys.queryOrderType
              },
              type: 'dropdownList',
              isMul: false,
              isMust: true
            },
            // 审核状态
            {
              compKey: 'compKey14',
              labelName: '供应商：',
              codeField: 'supplierId',
              textField: 'supplierShortName',
              component: () => import('@/views/ve/planReport/components/multipleSearchInput'),
              isMust: true,
              dataToObject: {
                // 控制弹窗页面 搜索 网格 元素
                oFields: 'supplierId,supplierShortName',
                tableComponents: [
                  {
                    compKey: 'compKey1',
                    labelName: '供应商编码：',
                    codeField: 'supplierId',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey2',
                    labelName: '供应商名称：',
                    codeField: 'supplierShortName',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  }
                ],
                tableCols: [
                  {
                    prop: 'supplierCode',
                    label: '供应商编码'
                  },
                  {
                    prop: 'supplierShortName',
                    label: '供应商名称'
                  }
                ],
                formField: {
                  supplierId: '',
                  supplierShortName: ''
                },
                returnField: {
                  prop: 'supplierId',
                  label: '供应商编码'
                },
                api: vehiclePdiPriceInquirys.queryPartSources
              },
              span: 6
            },
          ],
      // 动态组件-按钮
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          text: '查询',
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey4',
          type: '',
          size: 'small',
          clickEvent: () => this.exportExcel111(),
          text: this.$t('sys.button.export'),
          name: 'export',
          position: 'right' // 导出
        },
        {
          conmpKey: 'btenKey5',
          type: '',
          size: 'small',
          name: 'reset',
          text: '重置',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],
      formField: this.$utils.getFormField(this, {
        purOrderCode: '', // 订单号
        purDate: '', // 订货日期
        startDate: '',
        endDate: '',
        purOrderType: '', // 订单类型
        supplierCode: '',
        supplierId: '', // 供应商Id
        supplierShortName: '', // 供应商简称
        // dlrId: "" //供应商
      }),
      // 回调方法对象
      callbackObj: {
        // 网格点击回调事件
        onRowClick: currentRow => {
          this.onRightRowClick(currentRow)
        },
        // 手动勾选网格时，拿到勾选网格的数据
        // onCheckSelect: (selection, row) => {
        //   // console.log(selection, row,'111')
        //   this.selectiondata = selection
        // },
        onCheckSelectChange: selection => {
          this.selectiondata = selection
        }
      }
    }
  },
  watch:{
    'formField.startDate':{
      handler(val){
        if(val===""){
          console.log(111111111111)
          this.formField.startDate = ''
          this.formField.endDate = ''
          this.tableComponents[1].compKey=this.tableComponents[1].compKey+"1"
        }
      }
  },
  },
 
  mounted() {},
  methods: {
    close() {
      this.isViewPopWindows = false
    }
  },
  methods: {
    // 导出
    exportExcel111() {
      exportExcel(
        this.formField,
        vehiclePdiPriceInquirys.exportPartSaleOrderDlr.APIUrl,
        vehiclePdiPriceInquirys.exportPartSaleOrderDlr.ServiceCode,
        '备件采购订单查询_网点'
      )
    }
  }
}
</script>

<style>
</style>
